package com.hzh.cusviewdemo.Activity;

import androidx.appcompat.app.AppCompatActivity;

import android.animation.ObjectAnimator;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.daimajia.numberprogressbar.NumberProgressBar;
import com.daimajia.numberprogressbar.OnProgressBarListener;
import com.hzh.cusviewdemo.AnimationView.DyView.DYLoadingView;
import com.hzh.cusviewdemo.AnimationView.RippleAnimation.RippleAnimView;
import com.hzh.cusviewdemo.AnimationView.Shimmer.Shimmer;
import com.hzh.cusviewdemo.AnimationView.Shimmer.ShimmerTextView;
import com.hzh.cusviewdemo.AnimationView.VoicePlay.VoicePlayingIcon;
import com.hzh.cusviewdemo.AnimationView.WaveView;
import com.hzh.cusviewdemo.AnimationView.YWaveLoad.YWaveLoadView;
import com.hzh.cusviewdemo.R;
import com.hzh.cusviewdemo.AnimationView.Launcher.LauncherView;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Timer;
import java.util.TimerTask;

public class MainActivity extends AppCompatActivity implements OnProgressBarListener {

    private LinearLayout am_root;
    private DYLoadingView dyload;
    private ImageView am_p1;
    private YWaveLoadView waveLoad;
    private WaveView am_waveview;

    private NumberProgressBar bnp;
    private Timer timer;

    private ShimmerTextView am_shimmer;
    private Shimmer shimmer;

    private VoicePlayingIcon voicePlayingIcon;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        voicePlayingIcon = findViewById(R.id.voicePlayingIcon);
        waveLoad = findViewById(R.id.waveLoad);
        am_root = findViewById(R.id.am_root);
        am_waveview = findViewById(R.id.am_waveview);
        dyload = findViewById(R.id.dyload);
        am_p1 = findViewById(R.id.am_p1);
        bnp = findViewById(R.id.bnp);
        am_shimmer = findViewById(R.id.am_shimmer);

        final LauncherView launcherView = findViewById(R.id.load_view);
        findViewById(R.id.start).setOnClickListener(v -> {
            //关键代码
//            launcherView.start();
        });

        bnp.setOnProgressBarListener(this);
        timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                runOnUiThread(() -> bnp.incrementProgressBy(1));
            }
        }, 1000, 100);

    }

    public void clickRipple(View view) {
//        RippleAnimView.create(view, am_root).setDuration(500).start();
        ObjectAnimator.ofFloat(am_p1, "rotationX", 0f, 360f)
                .setDuration(2000)
                .start();
        // 开始动画
        dyload.start();
        // 开始声音动画
        voicePlayingIcon.start();
        // 开始水波加载图片动画
        waveLoad.startLoad();
        // 设置水波纹进度
        am_waveview.setProgressWithAnim(0.5f);
        // 开启文字闪动渐变
        shimmer = new Shimmer();
        shimmer.start(am_shimmer);
    }

    @Override
    public void onProgressChange(int current, int max) {
        if (current == max) {
            bnp.setProgress(0);
            timer.cancel();
        }
    }
}